﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LeadVinaglue.Models;
using LeadVinaglue.Models.ViewPages;
using System.Data.SqlClient;
using LeadVinaglue.Helpers;
using System.Data;

namespace LeadVinaglue.Repository
{
    public class DocumentTypeRepository : BaseManagementRepository
    {
        LeadVinaglueEntities entities = new LeadVinaglueEntities();


        #region Reference function
        public List<DocumentType> GetAll()
        {
            return (from _object in entities.DocumentTypes select _object).ToList();
        }

        public DocumentType GetSingle(int id)
        {
            return (from _object in entities.DocumentTypes where _object.TypeId == id select _object).FirstOrDefault();
        }
        
        public void Create([Bind(Exclude = "ID, DateCreated")] DocumentType _object)
        {
            entities.AddToDocumentTypes(_object);
            entities.SaveChanges();
        }

        public void Delete(int id)
        {
            var _object = (from _list in entities.DocumentTypes where _list.TypeId == id select _list).First();
            entities.DeleteObject(_object);
            entities.SaveChanges();
        }

        public void Save([Bind(Exclude = "ID")] DocumentType _object)
        {
            entities.SaveChanges();
        }

        #endregion
    }
}
